package com.towker.core.util;

import java.beans.PropertyEditorSupport;

import org.springframework.util.NumberUtils;
import org.springframework.util.StringUtils;

public class SpringNumberEditor extends PropertyEditorSupport {
	private Class numberClazz;
	public SpringNumberEditor(Class numberClazz) {
		this.numberClazz = numberClazz;
	}
	 @Override  
     public void setAsText(String text) throws IllegalArgumentException {  
         if(text == null ||text.equals(""))  
             text = "0";  
         if ( !StringUtils.hasText(text)) {  
             setValue(0);  
         }  
         else { 
        	 
             setValue(NumberUtils.parseNumber(text, numberClazz));
         }  
     }  
	 
     @Override  
     public String getAsText() {  
           
         return getValue().toString();  
     }  

}
